﻿Imports Kimmo

Public Class frmTablesTree
    Inherits System.Web.UI.Page
    Private WithEvents btNew As FineUI.Button
    Private WithEvents btRefresh As FineUI.Button
    Private strView As String = ""
    Private strID As String = ""
    Private strProjectID As String = ""
    Private strAction As String = ""
    
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        strView = WebSite.GetQueryValue("view")
        strAction = WebSite.GetQueryValue("action")
        strProjectID = WebSite.GetQueryValue("projectid")
        If Len(strView) > 0 Then clsDL.SaveSetting("view", strView)
        If Len(strAction) > 0 Then clsDL.SaveSetting("action", strAction)
        If Len(strProjectID) > 0 Then clsDL.SaveSetting("projectid", strProjectID)

        Me.btNew = clsFineUI.ToolBar.AddClickButton(tblLeft, "New", "~/images/newsomething16.gif", "Add a new table")
        Me.btRefresh = clsFineUI.ToolBar.AddClickButton(tblLeft, "Refresh", "~/images/refresh.gif", "Refresh tree")
    
        If IsPostBack Then
        Else
            clsProjects.TreeLoad(Me.treeViews)
            'If Len(strProjectID) > 0 Then
            'clsFineUI.TreeView.NodeExpand(treeViews, "project-" & strProjectID)
            'End If

            'If Len(strProjectID) > 0 Then
            'rgnMasterTables.IFrameUrl = "frmTables.aspx?a=v&p=&" & strProjectID
            'rgnMasterTables.RefreshIFrame()
            'End If
        End If

    End Sub

    Protected Sub Tables_Blank(ByVal strProjectID As String)
        clsTables.Tables_Blank(strProjectID)
        rgnMasterTables.IFrameUrl = "frmTables.aspx?view=tables&projectid=" & clsDL.ReadSetting("projectid")
        rgnMasterTables.RefreshIFrame()
    End Sub


    Public Sub treeViews_NodeExpand(sender As Object, e As FineUI.TreeExpandEventArgs) Handles treeViews.NodeExpand
        clsTables.TreeLoad(e.Node)
        
    End Sub

    Private Sub btRefresh_Click(sender As Object, e As EventArgs) Handles btRefresh.Click
        clsProjects.TreeLoad(Me.treeViews)
        clsDL.SaveSetting("id", "")
        clsDL.SaveSetting("projectid", "")
        clsDL.SaveSetting("view", "")
        rgnMasterTables.IFrameUrl = "frmTables.aspx"
        rgnMasterTables.RefreshIFrame()
    End Sub

    Private Sub btNew_Click(sender As Object, e As EventArgs) Handles btNew.Click
        Dim strProjectId As String = clsDL.ReadSetting("projectid")
        If Len(strProjectId) > 0 Then
            Tables_Blank(strProjectId)
        Else
            clsFineUI.MyAlert("Project Error", "Please select the project to add a table to first!")
        End If
    End Sub
End Class